import java.util.Random;
import java.util.Scanner;

public class GuessNumbers {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Random rand = new Random();
        int toguess = rand.nextInt(100);
        int count = 3;
        System.out.println("你有" + count + "次机会");
        //System.out.println(toguess);
        while(count != 0) {
            System.out.println("请输入你猜的数字：");
            int guess = sc.nextInt();
            if(guess == toguess) {
                System.out.println("恭喜你猜对了！答案是：" + guess);
                break;
            }else if(guess > toguess){
                count--;
                System.out.println("猜大了！");
                System.out.println("你还有" + count + "次机会");
            }else if(guess < toguess){
                count--;
                System.out.println("猜小了！");
                System.out.println("你还有" + count + "次机会");
            }
        }
        if(count == 0) {
            System.out.println("你的机会用完了！ 正确答案是：" + toguess);
        }
    }
}
